package com.fjt.book_trade.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.fjt.book_trade.dao.IOrderDao;
import com.fjt.book_trade.pojo.Order;

@Service("orderservice")
public class OrderService {
	private IOrderDao orderDao;
	private Order order;
	
	public IOrderDao getOrderDao() {
		return orderDao;
	}
	@Resource
	public void setOrderDao(IOrderDao orderDao) {
		this.orderDao = orderDao;
	}

	public Order getOrder() {
		return order;
	}
	@Resource(name="order")
	public void setOrder(Order order) {
		this.order = order;
	}

	public Order getUserOrderById(int order_id){
//		Map<String, Object> map=new HashMap<String, Object>();
		Order order=orderDao.selectOrderById(order_id);
		return order;
	}

	public Map<String, Object> getUserOrderlist(String username){
		Map<String, Object> map=new HashMap<String, Object>();
		List<Order> list=orderDao.selectUserAllOrder(username);
		if(list!=null){
			map.put("result", "success");
			map.put("OrderInfo", list);
		}else{
			map.put("result", "fail");
		}
		return map;
	}
	
	public Map<String, Object> getMySellOrderlist(String seller_name){
		Map<String, Object> map=new HashMap<String, Object>();
		List<Order> list=orderDao.selectMySellOrder(seller_name);
		if(list!=null){
			map.put("result", "success");
			map.put("OrderInfo", list);
		}else{
			map.put("result", "fail");
		}
		return map;
	}
	
	public Map<String, Object> getProductOrderlist(int product_id){
		Map<String, Object> map=new HashMap<String, Object>();
		List<Order> list=orderDao.selectProductAllOrder(product_id);
		if(list!=null){
			map.put("result", "success");
			map.put("OrdertInfo", list);
		}else{
			map.put("result", "fail");
		}
		return map;
	}
	public Map<String, Object> addOrder(Order order){
		Map<String, Object> map=new HashMap<String, Object>();
		if(orderDao.addOrder(order)){
			map.put("result", "success");
		}else{
			map.put("result", "fail");
		}
		return map;
	}
	public Map<String, Object> deleteOrder(int order_id){
		Map<String, Object> map=new HashMap<String, Object>();
		if(orderDao.deleteOrder(order_id)){
			map.put("result", "success");
		}else{
			map.put("result", "fail");
		}
		return map;
	}
	public Map<String,String> changeOrderState(int order_id,String state){//退货
		Map<String,String> map = new HashMap<String,String>();
		if(orderDao.changeOrderState(state, order_id)){
				map.put("result", "success");
		}else
			map.put("result", "fail");
		return map;
	}
	
	public Map<String,Object> AssessOrder(int order_id,String assess){//获得商品评价
		Map<String,Object> map = new HashMap<String,Object>();
		if(orderDao.assessOrder(assess, order_id)){
			map.put("result", "success");
		}else
			map.put("result", "error");
		return map;
	}
}
